// /**
//  * 返回切除匹配结果的字符串
//  * @param {String} str
//  * @param {Integer} index
//  */
// export function sliceMatchResult (str, matchResult) {
//     const resultLen = matchResult[0].length;
//     return str.substring(resultLen);
// }

export function isDef (value) {
    return value !== null
        && value !== undefined;
}

/**
 * 分析一个变量是否是基本类型
 * @param {any} target
 * @return {boolean}
 */
export function isPrimitive (target) {
    return (
        target === 'number'
        || target === 'string'
        || target === 'boolean'
    );
}

/**
 * 检测 target 变量是否是一个对象
 * @param {any} target
 * @return {boolean}
 */
export function isObject (target) {
    return target !== null && target instanceof Object;
}

const _toString = Object.prototype.toString;

/**
 * Strict object type check. Only returns true
 * for plain JavaScript objects.
 * @param {any} obj
 * @return {boolean}
 */
export function isPlainObject (obj) {
    return _toString.call(obj) === '[object Object]'
}

export function isArray (obj) {
    return Array.isArray(obj);
}

/**
 * Convert a value to a string that is actually rendered.
 * @param {any} val
 * @return {string}
 */
export function toString (val) {
    return val == null
        ? ''
        : Array.isArray(val) || (isPlainObject(val) && val.toString === _toString)
            ? JSON.stringify(val, null, 2)
            : String(val);
}

const hasOwnProperty = Object.prototype.hasOwnProperty;
export function hasOwn (obj, key) {
    return hasOwnProperty.call(obj, key);
}

/**
 * 将 _from 对象上的属性 赋值到 to 上, 不管 to 有没有
 * @param {Object} to
 * @param {Object} _from
 * @return {object}
 */
export function extend (to, _from) {
    for (let key in _from) {
        to[key] = _from[key];
    }
    return to;
}

/* istanbul ignore next */
export function isNative (Ctor) {
    return typeof Ctor === 'function' && /native code/.test(Ctor.toString())
}

